<div class="layui-fluid" id="user-password-update">
    <form class="layui-form" action="" lay-filter="password-update-form">
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">原密码：</label>
            <div class="layui-input-block">
                <input type="password" name="oldPassword" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">新密码：</label>
            <div class="layui-input-block">
                <input type="password" name="newPassword" minlength="6" lay-verify="range"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">密码确认：</label>
            <div class="layui-input-block">
                <input type="password" name="confirmPassword" minlength="6" lay-verify="range"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="password-update-form-submit" id="submit"></button>
        </div>
    </form>
</div>

<script>
    layui.use(['febs', 'form', 'validate', 'layer'], function () {
        let $ = layui.$,
            validate = layui.validate,
            form = layui.form,
            febs = layui.febs,
            user = layui.data('user').user,
            layer = layui.layer;

        form.verify(validate);
        form.render();

        form.on('submit(password-update-form-submit)', function (data) {

            if (data.field.newPassword !== data.field.confirmPassword) {
                febs.alert.warn('两次密码输入不一致！');
                return false;
            }
            febs.post(ctx + 'web/password/update',
                {
                    oldPassword: data.field.oldPassword,
                    newPassword: data.field.newPassword
                },
                function (r) {
                    if (r.code === 200) {
                        layer.closeAll();
                        febs.modal.success('修改成功', '密码修改成功，请重新登录', function () {
                            window.location.href = ctx + 'login';
                        });
                    }
                });
            return false;
        });
    });
</script>